package com.chima.service.impl;
import java.util.Date;
import java.util.List;
import org.hibernate.criterion.DetachedCriteria;
import com.chima.dao.JobDao;

import com.chima.domain.Job;
import com.chima.domain.PageRequestBean;
import com.chima.domain.PageResponseBean;
import com.chima.service.JobService;
public class JobServiceImp implements JobService{
	private JobDao jobDao;
	
	public JobDao getJobDao() {
		return jobDao;
	}

	public void setJobDao(JobDao jobDao) {
		this.jobDao = jobDao;
	}

	public PageResponseBean findData(PageRequestBean pageRequestBean)  {
		int firstResult =(pageRequestBean.getPage()-1)*pageRequestBean.getLimit();
		int maxResults =pageRequestBean.getLimit();
		int total = jobDao.findByTotalCount(pageRequestBean.getDate(),pageRequestBean.getEmp(), pageRequestBean.getJobstyle());
		// 获取分页查询条件
//		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Job.class);
		DetachedCriteria detachedCriteria = pageRequestBean.getCriteria();// 不一定存在
		List<Job> jobs = jobDao.findByCriteria(detachedCriteria, firstResult, maxResults);
		PageResponseBean pageResponseBean = new PageResponseBean();
		pageResponseBean.setRows(jobs);
		pageResponseBean.setTotal(total);
		return pageResponseBean;
	}

	public void saveJobs(Job job) {
		
		jobDao.save(job);
	}

	public void updateJobs(Job job) {
		jobDao.update(job);
		
	}

	public void deleteJobs(int id) {
		Job job =new Job();
		job.setId(id);
	    jobDao.delete(job);
	}

	public Job findJobById(int id) {
		return jobDao.findById(id);
		
	}

	public Job findJobByName(String name) {
		
		return jobDao.findByName(name);
	}

	public PageResponseBean InnovativeJob(PageRequestBean pageRequestBean) {
		int firstResult =(pageRequestBean.getPage()-1)*pageRequestBean.getLimit();
		int maxResults =pageRequestBean.getLimit();
		int total = jobDao.findByTotalCount1(pageRequestBean.getDate(),pageRequestBean.getEmp(), pageRequestBean.getJobstyle());
		// 获取分页查询条件
		DetachedCriteria detachedCriteria = pageRequestBean.getCriteria();// 不一定存在
		List<Job> jobs = jobDao.findByCriteria(detachedCriteria, firstResult, maxResults);
		PageResponseBean pageResponseBean = new PageResponseBean();
		pageResponseBean.setRows(jobs);
		pageResponseBean.setTotal(total);
		return pageResponseBean;
	}

	public Job findJobByNameAndDateAndDept(String name,Date date,int emp) {
		
		return jobDao.findByNameAndDateAnddept(name, date, emp);
	}

	
}